<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<h1>Applications for grants waiting for a decision the Director</h1>
<div class="col-md-9">

<c:if test="${not empty grantApplications}">

    <table class="table table-striped table-bordered table-hover">
        <thead>
        <tr>
            <td>Id</td>
            <td>Name</td>
            <td>Area</td>
            <td>User</td>
            <td>Money</td>
            <td>Controls</td>
        </tr>
        </thead>
        <tbody>
        <c:forEach var="grantApplication" items="${grantApplications}">
            <tr id="grantApp${grantApplication.grantId}">
                <td>${grantApplication.grantId}</td>
                <td>${grantApplication.grantName}</td>
                <td>${grantApplication.grantArea.name}</td>
                <td>${grantApplication.user.userLogin}</td>
                <td>${grantApplication.requestedMoney}</td>
                <td>
                    <button type="button" class="btn btn-success btn-sm"
                            onClick="acceptGrant(${grantApplication.grantId})">Accept
                    </button>
                    <button type="button" class="btn btn-danger btn-sm"
                            onClick="refuseGrant(${grantApplication.grantId})">Refuse
                    </button>
                </td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
    </div>
</c:if>

<script>
    function acceptGrant(id) {
        $.ajax({
            url: "../grant/accept/" + id,
            type: "GET",
            success: function () {
                $("#grantApp" + id).hide();
            }
        });
    }

    function refuseGrant(id) {
        $.ajax({
            url: "../grant/refuse/" + id,
            type: "GET",
            success: function () {
                $("#grantApp" + id).hide();
            }
        });
    }
</script>